package com.itzmn.newcode.offer;

import java.util.LinkedHashMap;

/**
 * @Author: 张梦楠
 * @Date: 2018/11/23 15:43
 * 简书：https://www.jianshu.com/u/d611be10d1a6
 * 码云：https://gitee.com/zhangqiye
 * @Description:  剑指Offer 找到数组中第一个重复的数字
 *
 *  思路：
 *      将数字存入linkedhashmap
 *
 *
 */
public  class FindFirstRepeatChar {

    public static void main(String[] args) {

        new FindFirstRepeatChar().duplicate(new int[]{1,2,3,4,2},5,new int[5]);
    }

    public boolean duplicate(int numbers[],int length,int [] duplication) {

        LinkedHashMap<Integer, Integer> map = new LinkedHashMap<>();

        for (int i=0;i<length;i++){
            if (map.get(numbers[i])==null){
                map.put(numbers[i],1);
            }else {
                duplication[0] = numbers[i];
                return true;
            }
        }

        return false;
    }


}
